import unittest
from time import sleep

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

from base.base_driver import driver_setup
from base.base_page import BasePage
from po.camera.camera_page import CameraPage
from po.common.common import Common
from po.home.home_page import HomePage
from HTMLTestReportCN import DirAndFiles


class Img2Excel(unittest.TestCase, BasePage):
    @classmethod
    def setUpClass(cls):
        cls.driver = driver_setup()
        cls.home_page = HomePage(driver=cls.driver)
        cls.camera_page = CameraPage(driver=cls.driver)
        cls.common = Common(driver=cls.driver)

    def test_01_img2excel(self):
        """拍图转Excel-横屏查看-复制"""
        self.home_page.func_policy_agree()
        self.home_page.btn_img2excel()
        self.camera_page.func_tip_close()
        self.camera_page.func_import_document_by_name("表格.pdf")
        DirAndFiles.get_screenshot(self.driver, "拍图转Excel")
        self.common.btn_land()
        WebDriverWait(self.driver, 200).until(EC.presence_of_element_located((By.ID, self.HW_ENV + "picnum")))
        sleep(1)
        DirAndFiles.get_screenshot(self.driver, "拍图转Excel_横屏查看")
        sleep(1)
        self.driver.keyevent(4)
        self.common.btn_copy()
        sleep(1)

    def test_02_export_excel(self):
        """拍图转Excel-导出excel"""
        self.common.func_edit_filename("拍图转Excel")
        self.common.btn_export()
        self.common.func_export()
        sleep(1)

    def test_03_export_pdf(self):
        """拍图转Excel-导出pdf"""
        self.common.btn_img_page()
        self.common.btn_export()
        self.common.func_export()
        sleep(1)

    def test_04_export_img(self):
        """拍图转Excel-导出图片"""
        self.common.btn_export()
        self.common.btn_img()
        self.common.func_export()
        sleep(1)
        self.driver.keyevent(4)

    @classmethod
    def tearDownClass(cls):
        cls.driver.quit()